package cn.dengta.webapp.user.model;

import java.util.HashMap;
import java.util.Map;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import cn.dengta.common.model.ValueProxy;
import cn.dengta.common.util.Common;
import cn.dengta.context.model.*;
import com.baomidou.mybatisplus.annotation.EnumValue;
import lombok.Getter;

@Getter
public enum Gender implements LabelI18nProxy<Gender, Integer> {

	/** 女 */
	FEMALE(0, UserEnumI18nKey.GENDER_FEMALE, "https://oss.flala6.com/internal/pic/female.png"),
	/** 男 */
	MALE(1, UserEnumI18nKey.GENDER_MALE, "https://oss.flala6.com/internal/pic/male.png"),
	//
	;

	public String avatar;
	// 定义私有变量
	@EnumValue
	public final Integer value;
	final ValueProxy<Gender, Integer> proxy;

	private static final Map<WesKit, Map<Gender, String>> avatars_default = new HashMap<>();

	static {
	}

	// 构造函数，枚举类型只能为私有
	Gender(Integer value, String label, String avatar) {
		this.value = value;
		this.avatar = avatar;
		this.proxy = new ValueProxy<>(this, value, label);
	}

	public static boolean isFemale(Gender gender) {
		return FEMALE == gender;
	}

	public boolean female() {
		return this == Gender.FEMALE;
	}

	public boolean male() {
		return this == Gender.MALE;
	}

	public static final Gender[] CACHE = values();

	public static Gender of(@Nullable Integer value) {
		return Common.getEnum(CACHE, Gender::getValue, value);
	}

	public Gender other() {
		return this == MALE ? FEMALE : MALE;
	}

	@Nonnull
	public static Gender getOrDefault(@Nullable Gender gender) {
		return gender == null ? MALE : gender;
	}

	public static String getOrDefaultAvatar(Gender gender, WesKit wesKit) {
		gender = getOrDefault(gender);
		if (wesKit != null && avatars_default.containsKey(wesKit)) {
			return avatars_default.get(wesKit).get(gender);
		}
		return gender.avatar;
	}

}
